#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   5.py
@Time    :   2020/05/04 21:49:12
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# 通过Python来模拟实现一个txt文件的拷贝过程;
# Start typing your code from here

import os,re

def kobbi(O,N):      #O为源文件位置  N为目标位置
    if os.path.isfile(O):
        if os.path.exists(N) == False:
            os.mkdir(N)

        if os.path.isdir(N):
            filename = os.path.basename(O)
            ret = re.match("^.+\.txt$",filename)
            if ret:
                try:
                    with open(O,"r",encoding="UTF-8") as o:
                        with open(os.path.join(N,filename),"w",encoding="UTF-8") as n:
                            n.write(o.read())
                except IOError as e:
                    raise e

kobbi("homework4/nup.txt","homework4/kobbi")